//
//  GameAlgorithm.h
//  PencilParkour
//  游戏算法 -- 四叉树、矩形碰撞、圆与矩形碰撞、矩形和直线碰撞等等
//  Created by longlingxiu on 14-7-30.
//
//

#ifndef __PencilParkour__GameAlgorithm__
#define __PencilParkour__GameAlgorithm__


/**
 
 算法
 
 **/
#include "cocos2d.h"
using namespace cocos2d;

#include <vector>


// 通用算法
class Algorithm {
    
public:
    
    static bool rectBoxColl( CCRect box1, CCRect box2 ); // 矩形碰撞
    
};

#define MAX_OBJECTS 10
#define MAX_LEVEL 5

//  四叉树
class QuadTree {
    
public:
    QuadTree( int, CCRect _bounds );
    ~QuadTree();
    
public:
    std::vector<QuadTree> nodes;
    CCArray* objects;
    int level;
    CCRect bounds;
public:
    
    int getIndex( CCRect box );
    
    void split();
    
    void insert( CCDictionary*);
    
    void insert( CCSprite*);
    
    std::vector<CCDictionary*> getCollVector( CCDictionary*  );
    
    std::vector<CCSprite*> getCollVector( CCSprite*  );
    
    CCArray* retrive( CCSprite*  );
    
    void clear();
    
};




#endif /* defined(__PencilParkour__GameAlgorithm__) */
